package com.weihuachao.repair;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.weihuachao.fragment.Main_fragment;
import com.weihuachao.fragment.Profile_fragment;

public class MainActivity extends FragmentActivity {

    private FragmentTabHost fragmentTabHost;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        fragmentTabHost= (FragmentTabHost) findViewById(android.R.id.tabhost);
        fragmentTabHost.setup(this,getSupportFragmentManager(),R.id.realtabcontent);
        String[] title=new String[]{
                "首页","个人中心"
        };
        int[] selectors=new int[]{
                R.drawable.main,
                R.drawable.mycenter
        };
        Class[] fragment =new Class[]{
                Main_fragment.class,
                Profile_fragment.class
        };
        LayoutInflater inflater=getLayoutInflater();
        for (int i=0;i<2;++i){
            View inflate=inflater.inflate(R.layout.tab_item,null);
            TextView textView= (TextView) inflate.findViewById(R.id.textview);
            textView.setText(title[i]);
            Drawable top=getResources().getDrawable(selectors[i]);
            textView.setCompoundDrawablesWithIntrinsicBounds(null,top,null,null);
            fragmentTabHost.addTab(fragmentTabHost.newTabSpec(title[i]).setIndicator(inflate),fragment[i],null);
        }
    }
}
